#include "counter.h"

Counter::Counter(QMutex *mutex, int *value)
{
    m_value = value;
    m_mutex = mutex;
}

void Counter::run()
{
    m_mutex->lock();    //We will wait untill we can lock!
    //our code here
    //有可能死锁
    QThread::currentThread()->msleep(50);
    *m_value = *m_value + 1;
    qInfo() << *m_value << QThread::currentThread();

    m_mutex->unlock();  //Other threads can lock!
}
